function getByte(src) {
  return fetch(src)
    .then(res => {
      return res.blob()
    })
    .then(data => { 
      return (data.size/1024).toFixed(2) + "KB"
    })
}

function showInfo(el, byte) { 
  const html = `真实尺寸:${el.naturalWidth}x${el.naturalHeight}\n显示尺寸:${el.width}x${el.height}\n存储大小:${byte}`
  el.title = html
}

document.addEventListener("mouseover", function (e) { 
  if (e.target.tagName === "IMG") { 
    getByte(e.target.src).then(byte => { 
      showInfo(e.target, byte);
    })
  }
}, true)

document.addEventListener("dragend", function (e) { 
  if (e.target.tagName === "IMG") { 
    // 发送消息
    chrome.runtime.sendMessage({
      type: "download",
      data: e.target.src
    })
  }
})